#include <bits/stdc++.h>
#define int long long
#define ldb long double
using namespace std;
int T, n, m, L, V;
int p[100005], sum[1000005];
bool mk[100005], sw[100005];
queue<int> cv;
struct car {
    int l, r;
} c[100005];
struct node {
    int p, t, x;
    bool operator<(const node &r) const {
        if (p != r.p) return p < r.p;
        return t < r.t;
    }
} e[200005];
int f1(int x, int y) {
    return floor((ldb)x / (ldb)y);
}
int f2(int x, int y) {
    return ceil((ldb)x / (ldb)y);
}
signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while (T--) {
        cin >> n >> m >> L >> V;
        for (int i=1;i<=n;i++) {
            int d, v, a;
            cin >> d >> v >> a;
            int l, r;
            if (a == 0)
                if (v > V) l = d, r = L;
                else l = r = -1;
            else {
                int x = d + f1(V*V - v*v, 2*a);
                int y = d + f2(V*V - v*v, 2*a);
                if (a > 0)
                    if (x >= L) l = r = -1;
                    else l = max(x+1, d), r = L;
                else if (y <= d) l = r = -1;
                else l = d, r = min(y-1, L);
            }
            c[i] = {l, r};
            e[i*2-1] = {l, 0, i};
            e[i*2] = {r, 1, i};
            sw[i] = 0;
        }
        for (int i=1;i<=1000000;i++) sum[i] = 0;
        for (int i=1;i<=m;i++) {
            cin >> p[i];
            sum[p[i]] = 1;
        }
        for (int i=1;i<=1000000;i++) sum[i] += sum[i-1];
        int cnt = 0;
        for (int i=1;i<=n;i++)
            if (c[i].l >= 0 && sum[c[i].r] - sum[c[i].l-1] > 0)
                cnt++, sw[i] = 1;
        cout << cnt << " ";
        cnt = 0;
        sort(e + 1, e + 1 + 2*n);
        int now = 1;
        for (int i=1;i<=n;i++) mk[i] = 0;
        while (!cv.empty()) cv.pop();
        for (int i=1;i<=2*n;i++) {
            if (!sw[e[i].x]) continue;
            if (e[i].t == 0) cv.push(e[i].x);
            else {
                if (mk[e[i].x]) continue;
                while (now < m && p[now+1] <= e[i].p) now++;
                while (!cv.empty())
                    if (p[now] >= c[cv.front()].l) mk[cv.front()] = 1, cv.pop();
                    else break;
                now++;
                cnt++;
            }
        }
        cout << m - cnt << "\n";
    }
    return 0;
}